home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 12 / Time Bases / TimeBaseSimple / TimeBaseSimple.p < prev    next >
Encoding:
Text File  |  1992-10-16  |  6.0 KB  |  249 lines  |  [TEXT/MPS ]

  1. {
  2.  
  3. }
  4.  
  5. PROGRAM TimeBaseSimple;
  6. { Shows basics about time bases. }
  7.  
  8. USES
  9.     MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, Traps, GestaltEqu, 
  10.     Movies, QuickTimeComponents, Strings;
  11.     
  12. CONST    rWindID = 128;
  13.         rRCTID = 128;
  14.         lastControl = 133;
  15.         arrowsID    = 133;
  16.         rectsCount = 14;
  17.         
  18. TYPE    BooleanPtr =     ^Boolean;
  19.  
  20.         TBState        =     RECORD
  21.                             tBase:        TimeBase;
  22.                             flags:        LONGINT;
  23.                             moovScale:    TimeScale;
  24.                             rate:        Fixed;
  25.                             prefRate:    Fixed;
  26.                             startTime:     TimeRecord;
  27.                             stopTime:     TimeRecord;
  28.                             zeroTime:    TimeRecord;
  29.                             currTime:    TimeRecord;
  30.                             duration:    TimeValue;
  31.                             clockName:    Str255;
  32.                         END;
  33.                         
  34.         RectsRecHandle = ^RectsRecPtr;
  35.         
  36.         RectsRecPtr = ^RectsRec;
  37.                         
  38.         RectsRec    =    RECORD
  39.                             rectCount: Integer;
  40.                             rects:        ARRAY [0..rectsCount] OF Rect;
  41.                           END;
  42.  
  43.  
  44. VAR        gMCPlay:        MovieController;
  45.         gWind:            WindowPtr;
  46.         gMoov:            Movie;
  47.         gSystemVersion:    Integer;
  48.         gDoneFlag:        Boolean;
  49.         
  50.         gErr:            OSErr;
  51.         gResult:        Boolean;
  52.         gEventRec:        EventRecord;
  53.         gMoovBox:        Rect;
  54.         
  55.         gLooping:        Boolean;
  56.         gShuttle:        ControlHandle;
  57.         gTBState:        TBState;
  58.         tr:                TimeRecord;
  59.         r:                 Rect;
  60.         gArrows:        PicHandle;
  61.         
  62. {$I TimeBaseSimpleAux.p} { Includes all auxiliary routines. }
  63.  
  64.  
  65. FUNCTION GetMovie: Movie;
  66.  
  67.     purpose         promp the user to select a file and then get a movie out of it
  68. }
  69.  
  70. VAR        reply:            StandardFileReply;
  71.         where:            Point;
  72.         localMoov:        Movie;
  73.         err:            OSErr;
  74.         movieResFile, 
  75.         resID:             Integer;
  76.         wasChanged:        Boolean;
  77.         moovResName:    Str255;
  78.         
  79. BEGIN
  80.     err := fnfErr;            { This is as good an error as any other }
  81.     IF DisplayGetFile('Please select movie file:',reply) THEN
  82.       BEGIN
  83.         err := OpenMovieFile(reply.sfFile, movieResFile, fsRdPerm);
  84.         IF  err = noErr THEN        
  85.           resID := 0;            { First 'moov' found }
  86.           err := NewMovieFromFile( localMoov, movieResFile, resID, moovResName, newMovieActive, wasChanged);
  87.           IF CloseMovieFile(movieResFile) <> noErr THEN
  88.             ErrorControl('Could not close the file');
  89.       END;
  90.     IF err = noErr THEN
  91.       GetMovie := localMoov
  92.     ELSE
  93.       GetMovie := nil;
  94. END;
  95.  
  96.  
  97. PROCEDURE SetUpControls(wind: WindowPtr);
  98. VAR     c:    ControlHandle;
  99.  
  100. BEGIN
  101.     gShuttle := GetNewControl(rWindID, gWind);
  102.     c := GetNewControl(rWindID+1, gWind);
  103.     c := GetNewControl(rWindID+2, gWind);
  104.     c := GetNewControl(rWindID+3, gWind);
  105.     c := GetNewControl(rWindID+4, gWind);
  106.     c := GetNewControl(rWindID+5, gWind);
  107. END;
  108.  
  109. FUNCTION SetUpMovie(moov: Movie; wind: WindowPtr; VAR mcPlay: MovieController): OSErr;
  110.  
  111.     purpose         given a window and a movie this routine sizes the
  112.                     window to fit the movie, gets the movie player by
  113.                     calling NewMovieController.
  114. }
  115.  
  116. VAR
  117.         err:             OSErr;
  118.         moovBox,
  119.         controllerBox:     Rect;
  120.         m: Movie;
  121.         
  122. BEGIN
  123.  
  124.     GetMovieBox(moov, moovBox);
  125.  
  126.     IF (((moovBox.right - moovBox.left) <= (gMoovBox.right - gMoovBox.left))
  127.       AND ((moovBox.bottom - moovBox.top) <= (gMoovBox.bottom - gMoovBox.top))) THEN
  128.       BEGIN
  129.         OffsetRect(moovBox, -(moovBox.left+gMoovBox.left), -(moovBox.top+gMoovBox.top));
  130.         SetMovieBox(moov, moovBox);
  131.       END
  132.     ELSE
  133.       BEGIN
  134.         SetMovieBox(moov, gMoovBox);
  135.       END;
  136.  
  137.     mcPlay := NewMovieController( moov, gMoovBox, mcTopLeftMovie);
  138.  
  139.     IF mcPlay = NIL THEN        { Could not get controller pass back some error }
  140.       BEGIN
  141.         err := internalQuickTimeError; { a.k.a. whatever error message             }
  142.         ErrorControl('Could not get controller for movie with MCNewMovieController');
  143.       END;
  144.       
  145.     err := MCEnableEditing(mcPlay, TRUE); 
  146.     err := MCDoAction(mcPlay, mcActionSetPlaySelection, Ptr(1));
  147.  
  148.     SetUpMovie := err;
  149. END;
  150.  
  151. (* There are some parameters that change on the fly and we need to
  152.    check them up every time we go through the event loop. The parameters
  153.    are:
  154.        shuttle position - shuttle need to rotate with the movie
  155.     rate - rate changes when movie is looping
  156.     duration - when a selection is made duration changes when playing.
  157.                note that while not playing the duration is set to the
  158.                whole movie to allow new selection
  159. *)
  160. PROCEDURE UpdateParams;
  161. VAR        startTimeValue,
  162.         stopTimeValue:    TimeValue;
  163.         duration: LONGINT;
  164.         aFix: Fixed;
  165.         r: Rect;
  166.         
  167. BEGIN
  168.     CallSetCtlValueNoProc(gShuttle, GetTimeBaseTime(gTBState.tBase, gTBState.moovScale, tr) DIV 10);
  169.     aFix := GetMovieRate(gMoov);
  170.     IF aFix <> gTBState.rate THEN
  171.       BEGIN
  172.         GetIndRect(rRCTID, 5, r);
  173.         InvalRect(r);
  174.         gTBState.rate := aFix;
  175.       END;
  176.     startTimeValue := GetTimeBaseStartTime(gTBState.tBase, gTBState.moovScale, gTBState.startTime);
  177.     stopTimeValue := GetTimeBaseStopTime(gTBState.tBase, gTBState.moovScale, gTBState.stopTime);
  178.     duration := stopTimeValue - startTimeValue;
  179.     IF duration <> gTBState.duration THEN
  180.       BEGIN
  181.         GetIndRect(rRCTID, 1, r);
  182.         InvalRect(r);
  183.         gTBState.duration := duration;
  184.         
  185.         GetIndRect(rRCTID, 10, r);
  186.         InvalRect(r);
  187.  
  188.         GetIndRect(rRCTID, 12, r);
  189.         InvalRect(r);
  190.       END;
  191.  
  192. END;
  193.  
  194. BEGIN (* MCSample *)
  195.  
  196.     IF InitSystem <> noErr THEN            { Initialize all managers             }
  197.       BEGIN
  198.         ErrorControl('Initialization failed');
  199.         Exit(PROGRAM);
  200.       END;
  201.  
  202.     gWind := GetNewCWindow(rWindID,NIL, WindowPtr(-1));
  203.     
  204.     SetUpControls(gWind); 
  205.     
  206.     SetPort(gWind);            { Make our window the current port    }
  207.     
  208.     REPEAT
  209.       BEGIN
  210.         InitVars;
  211.         gMoov := GetMovie;        { ask user to select a movie file     }
  212.         
  213.         IF gMoov = nil THEN    
  214.           BEGIN
  215.             { ErrorControl('Could not get the movie!;g'); }
  216.             LEAVE
  217.           END
  218.         ELSE            { if we have a movie then continue     }
  219.           BEGIN
  220.             InitControls(gMoov, gWind);
  221.             InvalRect(gWind^.portRect);
  222.             gErr := SetUpMovie(gMoov,gWind,gMCPlay);
  223.             IF gErr <> noErr THEN 
  224.               ErrorControl('Error at SetUpMovie')
  225.             ELSE
  226.               BEGIN
  227.                 WHILE NOT gDoneFlag DO
  228.                   BEGIN
  229.                     gResult := GetNextEvent(everyEvent, gEventRec);
  230.     (*                gResult := WaitNextEvent(everyEvent, gEventRec, 30, nil);                    *)
  231.     
  232.                     IF ( MCIsPlayerEvent(gMCPlay, gEventRec) = 0 ) THEN 
  233.                       BEGIN
  234.                         UpdateParams;                        { check for changes                 }
  235.                         IF gResult THEN                        { Player didn't handle the event }
  236.                           HandleEvent(gEventRec);             { Cliks in go away terminate app }
  237.                       END
  238.                   END;
  239.                 gErr := CloseComponent(gMCPlay);
  240.               END;
  241.             DisposeMovie(gMoov);
  242.           END
  243.       END
  244.     UNTIL FALSE;
  245.     DisposeWindow(gWind);
  246.     ExitMovies;
  247. END.